﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Input;

namespace AttentenceCheckSystem
{
    /// <summary>
    /// CalenderDay.xaml 的交互逻辑
    /// </summary>
    public partial class CalenderDay : UserControl
    {
        public static DependencyProperty IsHolidayProperty;

        static CalenderDay()
        {
            IsHolidayProperty = DependencyProperty.Register("IsHoliday",
                                    typeof(bool), typeof(CalenderDay),
                                     new PropertyMetadata(false, new PropertyChangedCallback(OnIsHolidayPropertyChanged)));
        }

        public CalenderDay()
        {
            InitializeComponent();
            IsHoliday = false;

        }

        static void OnIsHolidayPropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            CalenderDay dp = target as CalenderDay;
            dp.IsHoliday = (bool)e.NewValue;
        }

        private DateTime _day;

        public DateTime Day
        {
            set
            {
                DayText.Text = value.Day.ToString();
                MonthText.Text = value.Month.ToString();
                _day = value;
            }

            get{
                return _day;
            }
        }

        public bool IsHoliday{
            get { return (bool)GetValue(IsHolidayProperty); }
            set
            {
                SetValue(IsHolidayProperty, value);
                BrushConverter conv = new BrushConverter();

                if (value == true)
                {
                    Background.Fill = conv.ConvertFromString("AliceBlue") as System.Windows.Media.Brush;
                    setHoliday.IsEnabled = false;
                    cancelHoliday.IsEnabled = true;
                }
                else
                {
                    Background.Fill = conv.ConvertFromString("White") as System.Windows.Media.Brush;
                    setHoliday.IsEnabled = true;
                    cancelHoliday.IsEnabled = false;
                }
            }
        }

        private void setHoliday_Click(object sender, RoutedEventArgs e)
        {
            IsHoliday = true;
        }

        private void cancelHoliday_Click(object sender, RoutedEventArgs e)
        {
            IsHoliday = false;
        }
    }
}
